package com.ktwlsoft.archivemanage.domain.business.repositoryService.guiBusiness;

import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ktwlsoft.archivemanage.domain.dao.entity.Account;
import com.ktwlsoft.archivemanage.service.utils.DateUtils;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.repository.guiBusiness.IGuidanceApplyMapper;
import com.ktwlsoft.archivemanage.domain.dao.entity.guiBusiness.GuidanceApply;

/**
 * guidance_apply--指导申请业务层接口实现类
 *
 * @author zhuhe on 2020-04-28 14:05:03
 * @version 1.0
 */
@Service
public class GuidanceApplyRepositoryService {
	
	private final IGuidanceApplyMapper guidanceApplyMapper;

	public GuidanceApplyRepositoryService(IGuidanceApplyMapper guidanceApplyMapper) {
		this.guidanceApplyMapper = guidanceApplyMapper;
	}

	/**
 	 * 查询分页 on 2020-04-28 14:05:03
 	 * @param pn 第几页
     * @param pageSize 每页多少条
 	 * @param jsonObject jsonObject
 	 * @return PageInfo<GuidanceApply>
 	 */
	public PageInfo<GuidanceApply> findPage(int pn,int pageSize,JSONObject jsonObject) {
		PageHelper.startPage(pn,pageSize);
		PageInfo<GuidanceApply> pageInfo = new PageInfo<GuidanceApply>(guidanceApplyMapper.findList(jsonObject));
		return pageInfo;
	}

	/**
	 * 查询分页 on 2020-04-28 14:05:03
	 * @param pn 第几页
	 * @param pageSize 每页多少条
	 * @param jsonObject jsonObject
	 * @return PageInfo<GuidanceApply>
	 */
	public PageInfo<JSONObject> applyFindPage(int pn,int pageSize,JSONObject jsonObject){
		PageHelper.startPage(pn,pageSize);
		PageInfo<JSONObject> pageInfo = new PageInfo<JSONObject>(guidanceApplyMapper.findPage(jsonObject));
		return pageInfo;
	}

    /**
	 * 查询集合 on 2020-04-28 14:05:03
	 * @param jsonObject jsonObject
	 * @return List<GuidanceApply>
	 */
	public List<GuidanceApply> findList(JSONObject jsonObject) {
		return guidanceApplyMapper.findList(jsonObject);
	}

    /**
	 * 根据ID查询信息 on 2020-04-28 14:05:03
	 * @param id	主键
	 * @return GuidanceApply
	 */
	public GuidanceApply getById(Long id){
		return guidanceApplyMapper.getById(id);
	}

   /**
	 * 新增 on 2020-04-28 14:05:03
	 * @param guidanceApply guidanceApply
	 * @return int
	 */
	public int insert(GuidanceApply guidanceApply){
		return guidanceApplyMapper.insert(guidanceApply);
	}

	/**
	 * 批量插入 2020-04-28 14:05:03
	 *
	 * @param list list
	 * @return int
	 */
	public int manyInsert(List<GuidanceApply> list){
	    return guidanceApplyMapper.manyInsert(list);
	}

   /**
	 * 修改 on 2020-04-28 14:05:03
	 * @param guidanceApply guidanceApply
	 * @return int
	 */
	public int update(GuidanceApply guidanceApply){
		return guidanceApplyMapper.update(guidanceApply);
	}

   /**
	 * 根据id集合批量删除信息 on 2020-04-28 14:05:03
	 * @param guidanceApplyArr	主键编号集合
	 * @return int
	 */
	public int deleteByIds(List<Long> guidanceApplyArr){
		return guidanceApplyMapper.deleteByIds(guidanceApplyArr);
	}

   /**
	 * 根据id删除信息 on 2020-04-28 14:05:03
	 * @param id id
	 * @return int
	 */
	public int deleteById(Long id){
		return guidanceApplyMapper.deleteById(id);
	}

	/**
	  * 获取申请编号 on 2020/4/28 15:28
	  *
	  * @param account account
	  * @return String
	  */
	public String getApplyNum(Account account){
		String num = guidanceApplyMapper.getApplyNum(account.getId());
		if(num == null){
			return account.getUserName() + DateUtils.dateToStr(new Date(),"yyyyMMdd") + "001";
		}
		num = num.substring(num.length() - 3,num.length());
		int i = Integer.valueOf(num);
		i += 1;
		String newnum = String.valueOf(i);
		if(newnum.length() == 1){
			newnum = "00" + newnum;
		}else if(newnum.length() == 2){
			newnum = "0" + newnum;
		}
		return account.getUserName() + DateUtils.dateToStr(new Date(),"yyyyMMdd") + newnum;
	}
}
